package com.senlingspace.quartz.task;

import com.senlingspace.common.enums.EqumentStatus;
import com.senlingspace.common.enums.TeamStatus;
import com.senlingspace.system.domain.SlkTeamStatus;
import com.senlingspace.system.domain.SlkjTeamEqument;
import com.senlingspace.system.mapper.SlkTeamStatusMapper;
import com.senlingspace.system.mapper.SlkjTeamEqumentMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * 凌晨组队信息初始化
 *
 * @author lebronjames
 * @date 2024/07/26
 */
@Slf4j
@Component
@AllArgsConstructor
public class TeamStatusTask {

    private SlkTeamStatusMapper slkTeamStatusMapper;
    private SlkjTeamEqumentMapper slkjTeamEqumentMapper;


    @Scheduled(cron = "0 0 23 * * ?") // 每天23点执行一次
    @Transactional(rollbackFor = Exception.class)
    public void compensateOrderStatus() {
        log.info("凌晨23点 开始将组队状态修改为未使用");
        //        修改队伍的状态信息  slkj_team_status 改为 SUCCESS 已完成
        SlkTeamStatus slkTeamStatus = new SlkTeamStatus();
        slkTeamStatus.setTeamStatus(TeamStatus.INIT.getCode());
        slkTeamStatus.setCurNum(0);
        int i = slkTeamStatusMapper.initTeamStatus(slkTeamStatus);

        SlkjTeamEqument slkjTeamEqument = new SlkjTeamEqument();
        slkjTeamEqument.setStatus(EqumentStatus.SUCCESS.getCode());
        slkjTeamEqumentMapper.initTeamStatus(slkjTeamEqument);
        log.info("修改组队状态是未使用，共修改 "+i+"条");
    }

}
